package com.youcai.springboot_day04.contrlloer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


import java.util.List;
import java.util.Map;

@Controller
public class UserController {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @GetMapping("/aa")
    @ResponseBody
    public List<Map<String,Object>> finall(){
        String sql = "select * from student";
        List<Map<String, Object>> list_maps = jdbcTemplate.queryForList(sql);
        return list_maps;
    }

    @GetMapping("/bb")
    public String sava(){
        String sql = "insert into student(sname) values ('马志')";
       jdbcTemplate.update(sql);
        return "sava";

    }

    @GetMapping("/cc/{sno}")
    public String update(@PathVariable("sno") int sno){
        String sql = "update student set sname = ? where sno = " + sno ;
        Object[] objects = new Object[1];
        objects[0] = "小红";
        jdbcTemplate.update(sql,objects);
        return "om";
    }

    @GetMapping("/dd/{sno}")
    public String delete(@PathVariable("sno") int sno){
        String sql = "delete from student where  sno = ?";
        jdbcTemplate.update(sql,sno);
        return "qwe";
    }


}
